package cn.tao.org.controller;



import cn.tao.org.domain.Systemdictionarydetail;
import cn.tao.org.query.EmployeeQuery;
import cn.tao.org.query.SystemdictionarydetailQuery;
import cn.tao.org.service.IShopService;
import cn.tao.org.service.ISystemdictionarydetailService;
import cn.tao.utils.AjaxResult;
import cn.tao.utils.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/systemdictionarydetail")
public class SystemdictionarydetailController {

    @Autowired
    private ISystemdictionarydetailService systemdictionarydetailService;

    /**
     * 新增和修改
     * @RequestBody 接收一个json类型的对象
     * @param systemdictionarydetail
     * @return
     */
    @PutMapping
    public AjaxResult savAndUpt(@RequestBody Systemdictionarydetail systemdictionarydetail){
        try {
            if (systemdictionarydetail.getId() == null){
                systemdictionarydetailService.save(systemdictionarydetail);
            }else {
                systemdictionarydetailService.update(systemdictionarydetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    /**
     *("/{id}"):要与@PathVariable中的参数对应
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public AjaxResult delById(@PathVariable("id") Long id){
        try{
            systemdictionarydetailService.delete(id);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }

    /**
     * 根据id查询一个
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Systemdictionarydetail findEmployeeById(@PathVariable("id") Long id){
        return systemdictionarydetailService.loadById(id);
    }



    /**
     * 查询所有
     * @return
     */
    @GetMapping
    public List<Systemdictionarydetail> findEmployees(){
       return systemdictionarydetailService.loadAll();
    }


    /**
     * 高级查询和分页
     * @param query
     * @return
     */
    @PostMapping
    public QueryResult<Systemdictionarydetail> findEmployeeByQuery(@RequestBody SystemdictionarydetailQuery query){

        return systemdictionarydetailService.findByQuery(query);
    }

    /**
     * 批量删除
     * @param ids
     * @return
     */
    @PatchMapping
    public AjaxResult batchDelete(@RequestBody Long[] ids){
        try {
            systemdictionarydetailService.batchDelete(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage(e.getMessage());
        }
    }
}
